package cn.xuqiudong.sso.shiro.d20250228;

import java.time.LocalTime;
import java.util.concurrent.ThreadFactory;

/**
 * 描述:
 *
 * @author Vic.xu
 * @since 2025-02-28 15:02
 */
public class DelayedThreadFactory implements ThreadFactory {
    private final long delayMillis;

    public DelayedThreadFactory(long delayMillis) {
        this.delayMillis = delayMillis;
    }

    @Override
    public Thread newThread(Runnable r) {
        System.out.println(LocalTime.now() + " Thread creation started. will delay " + delayMillis + " millis.");
        try {
            // 模拟线程创建延迟
            Thread.sleep(delayMillis);
        } catch (InterruptedException e) {
            e.printStackTrace();
            Thread.currentThread().interrupt();
        }
        System.out.println(LocalTime.now() + " Thread created.");
        return new Thread(r);
    }
}